package com.affablebeans.model.repository;

import java.sql.SQLException;
import java.util.List;

import javax.sql.DataSource;

import com.affablebeans.model.bll.DefaultTrueValidator;
import com.affablebeans.model.bll.GenericEntityBLL;
import com.affablebeans.model.dal.CategoryDAL;
import com.affablebeans.model.entity.Category;

/**
 * 
 * @author Bora SAYINER
 * @since Jan 26, 2015 11:22:29 PM
 * @version 1.0.0
 */
public class Categories {

	private final GenericEntityBLL<Category> categoryBLL;

	public Categories(DataSource dataSource) {
		CategoryDAL categoryDAL = new CategoryDAL(dataSource);
		DefaultTrueValidator<Category> trueValidator = new DefaultTrueValidator<Category>();
		this.categoryBLL = new GenericEntityBLL<Category>(categoryDAL, trueValidator);
	}

	public boolean insertCategory(Category entity) throws SQLException {
		return categoryBLL.insertEntity(entity);
	}

	public boolean updateCategory(Category entity) throws SQLException {
		return categoryBLL.updateEntity(entity);
	}

	public boolean deleteCategory(Category entity) throws SQLException {
		return categoryBLL.deleteEntity(entity);
	}

	public Category findCategoryById(int id) throws SQLException {
		return categoryBLL.findEntityById(id);
	}

	public List<Category> getAllCategories() throws SQLException {
		return categoryBLL.getAllEntities();
	}

	public int getCount() throws SQLException {
		return categoryBLL.getEntitiesCount();
	}

}
